package com.cloud.tsp.service.impl;

import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import cn.hutool.poi.excel.StyleSet;
import com.alibaba.csp.sentinel.util.StringUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cloud.api.annotation.LocalLock;
import com.cloud.api.annotation.TransUser;
import com.cloud.core.util.R;
import com.cloud.core.exception.MyException;
import com.cloud.api.domain.forward.QueryVehicleSale;
import com.cloud.api.domain.forward.ResponseData;
import com.cloud.api.domain.screen.MapData;
import com.cloud.api.domain.screen.ModelSale;
import com.cloud.api.domain.stats.VehicleStats;
import com.cloud.api.domain.sys.SystemRoleDto;
import com.cloud.api.domain.tsp.*;
import com.cloud.api.utils.ExcelUtils;
import com.cloud.api.utils.ValidationUtils;
import com.cloud.api.constants.StrVo;
import com.cloud.mybatis.domain.TableDataInfo;
import com.cloud.tsp.mapper.VehicleSaleMapper;
import com.cloud.tsp.service.IVehicleProductionService;
import com.cloud.tsp.service.IVehicleSaleService;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import jakarta.annotation.Resource;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.ConstraintViolation;
import java.io.File;
import java.io.IOException;
import java.net.URLEncoder;
import java.text.MessageFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static com.cloud.tsp.service.impl.VehicleInformationServiceImpl.readExcelHeaders;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author haohaibo
 * @since 2023-12-20
 */
@Service("vehicleSaleService")
public class VehicleSaleServiceImpl extends ServiceImpl<VehicleSaleMapper, VehicleSale> implements IVehicleSaleService {

    @Resource
    private VehicleSaleMapper vehicleSaleMapper;
    @Resource
    private IVehicleProductionService vehicleProductionService;
    @Resource
    private MessageSource messageSource;
    @Resource(name = "myRedis")
    private RedisTemplate<String,Object> redisTemplate;
    @Autowired
    private StreamBridge streamBridge;

    @Override
    @TransUser
    public TableDataInfo<VehicleSale> selectVehicleSaleList(QueryVehicleProduction para) {
        Page<VehicleSale> page = new Page<>();
        page.setCurrent(para.getPage());
        page.setSize(para.getPageSize());
        IPage<VehicleSale> data = vehicleSaleMapper.selectVehicleSaleList(page, para);
        desensitize(data.getRecords());
        return TableDataInfo.build(data);
    }

    public void desensitize(List<VehicleSale> list){
        for (VehicleSale vehicleSale : list) {
            vehicleSale.setVin(StrUtil.hide(vehicleSale.getVin(), 8, 11));
            if (StringUtil.isNotBlank(vehicleSale.getLicenseNumber())){
                if ("oil".equals(vehicleSale.getVehicleType())){
                    vehicleSale.setLicenseNumber(StrUtil.hide(vehicleSale.getLicenseNumber(), 3, 6));
                }else {
                    vehicleSale.setLicenseNumber(StrUtil.hide(vehicleSale.getLicenseNumber(), 4, 7));
                }
            }
        }
    }

    @Override
    public Long selectVehicleCountByDept(List<String> deptId) {
        LambdaQueryWrapper<VehicleSale> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(VehicleSale::getDeptId,deptId);
        return vehicleSaleMapper.selectCount(queryWrapper);
    }

    @Override
    public VehicleStats selectVehicleCount() {
        LambdaQueryWrapper<VehicleSale> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(VehicleSale::getVehicleType,"ev");
        VehicleStats vehicleStats = new VehicleStats();
        Long total = vehicleSaleMapper.selectCount(null);
        Long evTotal = vehicleSaleMapper.selectCount(queryWrapper);

        queryWrapper.clear();
        queryWrapper.eq(VehicleSale::getVehicleType,"oil");
        Long oilTotal = vehicleSaleMapper.selectCount(queryWrapper);
        vehicleStats.setTotal(total);
        vehicleStats.setOilTotal(oilTotal);
        vehicleStats.setEvTotal(evTotal);
        return vehicleStats;
    }

    @Override
    public TableDataInfo<VehicleSale> selectVehicleForwardList(QueryVehicleSale para) {
        Page<VehicleSale> page = new Page<>();
        page.setCurrent(para.getPage());
        page.setSize(para.getPageSize());
        IPage<VehicleSale> data = vehicleSaleMapper.selectVehicleForwardList(page, para);
        desensitize(data.getRecords());
        return TableDataInfo.build(data);
    }

    @Override
    public VehicleBaseVo selectVehicleBaseInformation(String id) {
        return vehicleSaleMapper.selectVehicleBaseInformation(id);
    }

    @Override
    public void updateByIds(BatchId para) {
        List<String> ids = para.getIds();
        List<VehicleSale> list = new ArrayList<>();
        for (String id : ids){
            VehicleSale vehicleSale = new VehicleSale();
            vehicleSale.setId(id);
            vehicleSale.setDeptId(para.getDeptId());
            list.add(vehicleSale);
        }
        this.updateBatchById(list);
        /*List<VehicleSale> saleList = vehicleSaleMapper.selectBatchIds(ids);
        for (VehicleSale vehicleSale : saleList){
            redisTemplate.opsForHash().put("VIN-INFORMATION",vehicleSale.getVin(),vehicleSale);
        }*/
    }

    @Override
    public void insertOrUpdate(VehicleSale para) {
        if (StringUtil.isBlank(para.getId())){
            VehicleProduction data = vehicleProductionService.selectByVin(para.getVin());
            if (data == null){
               throw new MyException("wds.exception.productNoVin");
            }
            para.setModelBrand(data.getModelBrand());
            para.setModelSeries(data.getModelSeries());
            para.setModelType(data.getModelType());
            para.setVehicleType(data.getVehicleType());
            para.setDid(data.getDid());
        }else {
//            redisTemplate.opsForHash().delete("VIN-INFORMATION",para.getVin());
            para.setVin(null);
            para.setModelBrand(null);
            para.setModelSeries(null);
            para.setModelType(null);
            para.setVehicleType(null);
            para.setDid(null);
        }
        if (!checkExist(para.getVin())){
            throw new MyException("wds.exception.vinRepeat");
        }
        this.saveOrUpdate(para);
//        VehicleSale vehicleSale = vehicleSaleMapper.selectById(para.getId());
//        redisTemplate.opsForHash().put("VIN-INFORMATION",vehicleSale.getVin(),vehicleSale);
        streamBridge.send("VEH_CHANGE-out-0", MessageBuilder.withPayload("VEH_CHG").build());
    }

    @Override
    public List<VinLockStatus> selectVinScopeTsp(String vin) {
        Page<VehicleSale> page = new Page<>(1,10);
//        QueryVehicle permissions = getPermissions();
//        return vehicleSaleMapper.selectVinScopeTsp(permissions);
        List<VinLockStatus> list = vehicleSaleMapper.selectVinScopeTsp(page, vin);
        for (VinLockStatus strVo : list){
            strVo.setVin(StrUtil.hide(strVo.getVin(), 8, 11));
        }
        return list;
    }

    /*public QueryVehicle getPermissions(){
        QueryVehicle para = new QueryVehicle();
        para.setDataScope(LoginHelper.getDataScope());
        String userDept = LoginHelper.getUserLogin().getDeptId();
        if (para.getDataScope() == 5){
            R<SystemRoleDto> roleDetail = systemRoleOpenFeignService.getById(new StrVo(LoginHelper.getUserLogin().getRoleId()));
            String[] split = roleDetail.getData().getDeptIds().split(",");
            List<String> deptIds = new ArrayList<>(Arrays.asList(split));
            para.setDeptIds(deptIds);
        }else {
            List<String> list = new ArrayList<>();
            list.add(userDept);
            para.setDeptIds(list);
        }
        return para;
    }*/

    public boolean checkExist(String vin) {
        LambdaQueryWrapper<VehicleSale> wrapper = new QueryWrapper().lambda();
        wrapper.eq(VehicleSale::getVin,vin);
        List<VehicleSale> list = vehicleSaleMapper.selectList(wrapper);
        return list.size() == 0;
    }

    @Override
    public void downloadTemplate(HttpServletResponse response) throws IOException {
        Locale locale = LocaleContextHolder.getLocale();
        String fileName = "table.saleName";
        String message = messageSource.getMessage(fileName, null, fileName, locale);
        Map<String, String> map = translateFields(locale);

        ExcelWriter excelWriter = ExcelUtil.getWriter(message+".xlsx");
        excelWriter.setColumnWidth(0, 20);
        excelWriter.setColumnWidth(1, 20);
        excelWriter.setColumnWidth(2, 33);
        excelWriter.setColumnWidth(3, 20);
        excelWriter.setColumnWidth(4, 20);
        excelWriter.setColumnWidth(5, 20);
        excelWriter.setColumnWidth(6, 20);
        excelWriter.setColumnWidth(7, 20);
        excelWriter.setColumnWidth(8, 20);
        StyleSet styleSet = excelWriter.getStyleSet();
        styleSet.setBackgroundColor(IndexedColors.YELLOW1,false);
        excelWriter.writeRow(Arrays.asList(map.get("num"),map.get("vin1"),map.get("saleDate1"),map.get("carOwner1"),map.get("carPhone1"),map.get("licenseNumber"),map.get("province1"),map.get("city1"),map.get("district1")));
        response.setContentType("application/vnd.ms-excel;charset=utf-8");
        response.setHeader("Content-Disposition", "attachment;filename*=" + URLEncoder.encode(message+".xlsx", "UTF-8"));
        try {
            Workbook workbook = excelWriter.getWorkbook();
            CellStyle cellStyle = workbook.createCellStyle();
            Sheet sheet = workbook.getSheetAt(0);
            Row row = sheet.getRow(0);
            Cell cell = row.getCell(1);
            String r = ((XSSFCell) cell).getCTCell().getR();
            r = r.substring(0, 1);
            // 设置数据验证
            DataValidationHelper helper = sheet.getDataValidationHelper();
            CellRangeAddressList addressList = new CellRangeAddressList(1, 600, 1, 1);
            //vin唯一
            DataValidationConstraint constraint = helper.createCustomConstraint(MessageFormat.format("COUNTIF({0}:{0},{0}2)=1",r));
            DataValidation dataValidation = helper.createValidation(constraint, addressList);
            dataValidation.createErrorBox("错误：", "vin不允许重复");
            dataValidation.setShowErrorBox(true);
            dataValidation.setEmptyCellAllowed(true);
            dataValidation.setSuppressDropDownArrow(true);
            dataValidation.setShowPromptBox(true);
            dataValidation.setErrorStyle(DataValidation.ErrorStyle.STOP);

            sheet.addValidationData(dataValidation);

            //设置列为文本格式
            DataFormat format = workbook.createDataFormat();
            cellStyle.setDataFormat(format.getFormat("@"));
            excelWriter.setColumnStyle(1,cellStyle);
            ServletOutputStream out=response.getOutputStream();
            workbook.write(out);
            workbook.close();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void exportSaleVinList(QueryVehicleProduction para, HttpServletResponse response) throws IOException {
        Locale locale = LocaleContextHolder.getLocale();
        String fileName = "table.saleName";
        String message = messageSource.getMessage(fileName, null, fileName, locale);
        Map<String, String> map = translateFields(locale);
        ExcelWriter bigWriter = ExcelUtil.getBigWriter();
        List<VehicleSale> list = vehicleSaleMapper.selectAllVehicleSaleList(para);
        list.forEach(a->a.setVehicleType("ev".equals(a.getVehicleType())?"新能源":"油车"));
        bigWriter.setColumnWidth(0, 20);
        bigWriter.setColumnWidth(1, 20);
        bigWriter.setColumnWidth(2, 20);
        bigWriter.setColumnWidth(3, 20);
        bigWriter.setColumnWidth(4, 20);
        bigWriter.setColumnWidth(5, 20);
        bigWriter.setColumnWidth(6, 20);
        bigWriter.setColumnWidth(7, 20);
        bigWriter.setColumnWidth(8, 20);
        bigWriter.setColumnWidth(9, 20);
        bigWriter.setColumnWidth(10, 20);
        bigWriter.addHeaderAlias("vin", map.get("vin"));
        bigWriter.addHeaderAlias("vehicleType", map.get("vehicleType"));
        bigWriter.addHeaderAlias("modelName", map.get("model"));
        bigWriter.addHeaderAlias("deptName", map.get("organization"));
        bigWriter.addHeaderAlias("saleDate", map.get("saleDate"));
        bigWriter.addHeaderAlias("carOwner", map.get("carOwner"));
        bigWriter.addHeaderAlias("phoneNumber", map.get("carPhone"));
        bigWriter.addHeaderAlias("licenseNumber", map.get("licenseNumber"));
        bigWriter.addHeaderAlias("province", map.get("province"));
        bigWriter.addHeaderAlias("city", map.get("city"));
        bigWriter.addHeaderAlias("district", map.get("district"));
        bigWriter.addHeaderAlias("did", map.get("did"));
        bigWriter.setOnlyAlias(true);
        CellStyle headCellStyle = bigWriter.getHeadCellStyle();
        headCellStyle.setFillBackgroundColor((short) 5);
        bigWriter.write(list);
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
//        response.setContentType("application/vnd.ms-excel;charset=utf-8");
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(message+".xlsx", "UTF8"));
        response.setCharacterEncoding("UTF-8");
        response.addHeader("Pargam", "no-cache");
        response.addHeader("Cache-Control", "no-cache");
        try {
            Workbook workbook = bigWriter.getWorkbook();
            ServletOutputStream out=response.getOutputStream();
            workbook.write(out);
            workbook.close();
            out.close();
            bigWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    @LocalLock(key = "import",value = "#{key}", expire = 10000)
    public ResponseData importSaleVinList(String deptId, MultipartFile file, HttpServletResponse response, String key) throws IOException {
        Locale locale = LocaleContextHolder.getLocale();

        //检查表头
        List<String> excelHeaders = readExcelHeaders(file);
        List<String> header = ExcelUtils.getExcelImportFieldsName(VehicleSaleExcel.class);
        if (!header.equals(excelHeaders)) {
            throw new MyException("wds.exception.importHeaderError");
        }

        List<VehicleSaleExcel> list = ExcelUtils.read(file, VehicleSaleExcel.class);
        if (list.size() > 500){
            throw new MyException("wds.exception.importData");
        }
        //定义导出错误集合
        List<VehicleSaleExcel> fail = new ArrayList<>();
        //检查excel中的vin是否重复
        List<String> ExcelRepeat = checkData(list, fail);
        list.removeIf(VehicleSaleExcel -> ExcelRepeat.contains(VehicleSaleExcel.getNum()));

        //注解校验 格式错误的vin需要移出去到错误集合中
        checkValidation(list,fail,locale);

        //查询库中是否包含vin,返回正确的vin集合
        List<String> collect = chekDataSource(list, fail,locale);

        List<VehicleSale> saveList = new ArrayList<>();
        //查询生产表中的数据,移除生产数据中没有的vin
        checkProductData(list,fail,saveList,collect,deptId,locale);

        this.saveBatch(saveList);
        if (!saveList.isEmpty()){
            streamBridge.send("VEH_CHANGE-out-0", MessageBuilder.withPayload("VEH_CHG").build());
        }
        /*for (VehicleSale vehicleSale : saveList){
            redisTemplate.opsForHash().put("VIN-INFORMATION",vehicleSale.getVin(),vehicleSale);
        }*/
        String fileName = null;
        if (fail.size() > 0){
            //导出fail
            fileName = exportErrList(fail, response);
        }
        ResponseData responseData = new ResponseData();
        responseData.setFileName(fileName);
        return responseData;
    }

    @Override
    public List<VehicleSale> getSaleCount() {
        return vehicleSaleMapper.getSaleCount();
    }

    @Override
    public List<ModelSale> getSaleCountTop5() {
        return vehicleSaleMapper.getSaleCountTop5();
    }

    @Override
    public List<VehicleSale> getSaleCountTop10() {
        return vehicleSaleMapper.getSaleCountTop10();
    }

    @Override
    public List<MapData> getSaleCountMap() {
        return vehicleSaleMapper.getSaleCountMap();
    }

    @Override
    public VehicleSale selectVehicleSaleByVin(String vin) {
        LambdaQueryWrapper<VehicleSale> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(VehicleSale::getVin,vin);
        return vehicleSaleMapper.selectOne(queryWrapper);
    }

    public void checkProductData(List<VehicleSaleExcel> list,List<VehicleSaleExcel> fail,List<VehicleSale> saveList,List<String> collect,String dept,Locale locale){
        Map<String, Map<String, String>> modelMap = getData(collect);
        for (VehicleSaleExcel vehicleSaleExcel : list){
            Map<String, String> model = modelMap.get(vehicleSaleExcel.getVin());
            if (model == null){
                String message = messageSource.getMessage("validation.sale.notExistVin", null, locale);
                vehicleSaleExcel.setErrResult(message);
                fail.add(vehicleSaleExcel);
                continue;
            }
            VehicleSale vehicleSale = new VehicleSale();
            BeanUtils.copyProperties(vehicleSaleExcel,vehicleSale);
            vehicleSale.setVehicleType(model.get("vehicleType"));
            vehicleSale.setModelBrand(model.get("modelBrand"));
            vehicleSale.setModelSeries(model.get("modelSeries"));
            vehicleSale.setModelType(model.get("modelType"));
            vehicleSale.setDeptId(dept);
            vehicleSale.setDid(model.get("did"));
            saveList.add(vehicleSale);
        }
    }

    public List<String> chekDataSource(List<VehicleSaleExcel> list,List<VehicleSaleExcel> fail,Locale locale){
        List<VehicleSale> repeatList = new ArrayList<>();
        List<String> collect = list.stream().map(VehicleSaleExcel::getVin).collect(Collectors.toList());
        if (collect.size() > 0){
            LambdaQueryWrapper<VehicleSale> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.in(VehicleSale::getVin,collect);
            repeatList = vehicleSaleMapper.selectList(queryWrapper);
        }
        List<String> repeat = repeatList.stream().map(VehicleSale::getVin).collect(Collectors.toList());

        if (repeat.size() > 0){
            for (VehicleSaleExcel v : list){
                if (repeat.contains(v.getVin())){
                    String message = messageSource.getMessage("validation.sale.vinExist", null, locale);
                    v.setErrResult(message);
                    fail.add(v);
                }
            }
            //移除数据库中存在的数据
            list.removeIf(vehicle -> repeat.contains(vehicle.getVin()));
            collect = list.stream().map(VehicleSaleExcel::getVin).collect(Collectors.toList());
        }
        return collect;
    }

    public void checkValidation(List<VehicleSaleExcel> list,List<VehicleSaleExcel> fail,Locale locale){
        List<String> errVin = new ArrayList<>();
        list.forEach(a ->{
            Set<ConstraintViolation<VehicleSaleExcel>> violations = ValidationUtils.getValidator().validate(a);
            List<String> error = new ArrayList<>();
            violations.forEach(b -> {
                String err = transErr(b.getMessage(), locale);
                error.add(err);
            });
            if(violations.size()>0){
                a.setErrResult(error.toString());
                fail.add(a);
                errVin.add(a.getVin());
            }
        });
        list.removeIf(vehicle -> errVin.contains(vehicle.getVin()));
    }

    public List<String> checkData(List<VehicleSaleExcel> list,List<VehicleSaleExcel> fail){
        Locale locale = LocaleContextHolder.getLocale();
        List<String> repeatList = new ArrayList<>();
        Map<String, Integer> map = new HashMap<>();
        for (VehicleSaleExcel v : list) {
            if (map.containsKey(v.getVin())) {
                repeatList.add(v.getNum());
                Integer num = map.get(v.getVin());
                map.put(v.getVin(), num + 1);
                String message = messageSource.getMessage("validation.sale.ExcelRepeatVin", null, locale);
                v.setErrResult(message);
                fail.add(v);
            } else {
                map.put(v.getVin(), 1);
            }
        }
        return repeatList;
    }

    public String exportErrList(List<VehicleSaleExcel> fail,HttpServletResponse response)throws IOException{
        /*Locale locale = LocaleContextHolder.getLocale();
        String fileName = "table.saleNameErr";
        fileName = messageSource.getMessage(fileName, null, fileName, locale);
        ExcelUtils.export(response,fileName,fail,VehicleSaleExcel.class);*/
        String basePath = "/data/cglx/errFiles/";
        String fileName = UUID.randomUUID().toString()+".xlsx";
        ExcelUtils.export(new File(basePath+fileName),fail, VehicleSaleExcel.class);
        return fileName;
    }

    public Map<String,Map<String,String>> getData(List<String> list){
        if (list.size() == 0){
            return null;
        }
        Map<String,Map<String,String>> vinMap = new HashMap<>();
        LambdaQueryWrapper<VehicleProduction> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(VehicleProduction::getVin,list);
        List<VehicleProduction> productions = vehicleProductionService.list(queryWrapper);

        for (VehicleProduction v : productions){
            Map<String,String> model = new HashMap<>();
            model.put("vehicleType",v.getVehicleType());
            model.put("modelBrand",v.getModelBrand());
            model.put("modelSeries",v.getModelSeries());
            model.put("modelType",v.getModelType());
            model.put("did",v.getDid());
            vinMap.put(v.getVin(),model);
        }
        return vinMap;
    }

    public String transErr(String err,Locale locale){
        Pattern pattern = Pattern.compile("\\{(.*?)\\}");
        Matcher matcher = pattern.matcher(err);
        if (matcher.find()){
            return messageSource.getMessage(matcher.group(1), null, matcher.group(1), locale);
        }
        return err;
    }

    public Map<String, String> translateFields(Locale locale){
        Map<String,String> map = new HashMap<>();
        String num = "table.field.num";
        String vin = "table.field.vin";
        String vin1 = "table.field.*vin";
        String saleDate = "table.field.saleDate";
        String saleDate1 = "table.field.*saleDate";
        String carOwner = "table.field.carOwner";
        String carOwner1 = "table.field.*carOwner";
        String carPhone = "table.field.carPhone";
        String carPhone1 = "table.field.*carPhone";
        String licenseNumber = "table.field.licenseNumber";
        String model = "table.field.model";
        String organization = "table.field.organization";
        String province = "table.field.province";
        String province1 = "table.field.*province";
        String city = "table.field.city";
        String city1 = "table.field.*city";
        String district = "table.field.district";
        String district1 = "table.field.*district";
        String did = "table.field.did";


        map.put("vin",messageSource.getMessage(vin, null, vin, locale));
        map.put("vin1",messageSource.getMessage(vin1, null, vin1, locale));
        map.put("num",messageSource.getMessage(num, null, num, locale));
        map.put("carOwner",messageSource.getMessage(carOwner, null, carOwner, locale));
        map.put("carOwner1",messageSource.getMessage(carOwner1, null, carOwner1, locale));
        map.put("carPhone",messageSource.getMessage(carPhone, null, carPhone, locale));
        map.put("carPhone1",messageSource.getMessage(carPhone1, null, carPhone1, locale));
        map.put("licenseNumber",messageSource.getMessage(licenseNumber, null, licenseNumber, locale));
        map.put("saleDate",messageSource.getMessage(saleDate, null, saleDate, locale));
        map.put("saleDate1",messageSource.getMessage(saleDate1, null, saleDate1, locale));
        map.put("model",messageSource.getMessage(model, null, model, locale));
        map.put("organization",messageSource.getMessage(organization, null, organization, locale));
        map.put("province",messageSource.getMessage(province, null, province, locale));
        map.put("province1",messageSource.getMessage(province1, null, province1, locale));
        map.put("city",messageSource.getMessage(city, null, city, locale));
        map.put("city1",messageSource.getMessage(city1, null, city1, locale));
        map.put("district",messageSource.getMessage(district, null, district, locale));
        map.put("district1",messageSource.getMessage(district1, null, district1, locale));
        map.put("did",messageSource.getMessage(did, null, did, locale));
        return map;
    }
}